import { initDatabase } from '../config/database.js';
import db from '../config/database.js';

console.log('🔄 Initializing database...');

// Initialize tables
initDatabase();

// Insert default categories
const categories = [
  { name: '连衣裙', name_en: 'Dresses', description: 'African style dresses', display_order: 1 },
  { name: '套装', name_en: 'Sets', description: 'Complete outfit sets', display_order: 2 },
  { name: '蕾丝布料', name_en: 'Lace Fabrics', description: 'Quality lace materials', display_order: 3 },
  { name: '配饰', name_en: 'Accessories', description: 'Fashion accessories', display_order: 4 }
];

const insertCategory = db.prepare(`
  INSERT OR IGNORE INTO categories (name, name_en, description, display_order)
  VALUES (?, ?, ?, ?)
`);

categories.forEach(cat => {
  insertCategory.run(cat.name, cat.name_en, cat.description, cat.display_order);
});

console.log('✅ Default categories created');

// Insert default store info
const storeInfo = {
  site_name: 'Lucy African Fashion',
  site_description: 'Your trusted African Wear Supplier from China',
  welcome_text: 'Welcome to Lucy African Fashion – Your trusted African Wear Supplier from China.',
  about_text: 'We are located in Yulong Garment City, Yuexiu District, Guangzhou, specializing in African women\'s fashion wholesale.',
  address: 'Yulong Garment City, Yuexiu District, Guangzhou, China',
  whatsapp: '+86 123 4567 8900',
  wechat: 'lucyfashion',
  instagram: '@lucyafricanfashion',
  email: 'contact@lucyfashion.com',
  phone: '+86 123 4567 8900',
  shipping_info: 'We support DHL, air freight, and sea freight shipping options.',
  logo: '',
  banner: '',
  wechat_qr: '',
  store_images: '[]'
};

const insertStoreInfo = db.prepare(`
  INSERT OR IGNORE INTO store_info (key, value)
  VALUES (?, ?)
`);

Object.entries(storeInfo).forEach(([key, value]) => {
  insertStoreInfo.run(key, typeof value === 'object' ? JSON.stringify(value) : value);
});

console.log('✅ Default store info created');
console.log('✅ Database initialization completed!');

db.close();

